//
//  HRLeftMenuCell.m
//  Hear
//
//  Created by mac on 2017/3/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRLeftMenuCell.h"
@interface HRLeftMenuCell ()


@end
@implementation HRLeftMenuCell




+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRLeftMenuCell";
    
    HRLeftMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRLeftMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        UIImageView *iconImageView = [UIImageView new];
        iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        iconImageView.clipsToBounds = YES;
        [self addSubview:(_iconImageView = iconImageView)];
        
        
        UILabel *descLabel = [UILabel new];
        descLabel.textColor = [UIColor whiteColor];
        descLabel.font = CustomUIFont(14);
        [self addSubview:(_descLabel = descLabel)];
        
        UISwitch *switchView = [[UISwitch alloc] init];
        [switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];   // 开关事件切换通知
//         switchView.on = YES;//设置初始为ON的一边
        switchView.onTintColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];
        
        [self addSubview:(self.switchView = switchView)];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isButtonOn"] intValue] == 10){
            switchView.on = YES;
        }else{
            switchView.on = NO;
        }
        
        UILabel *manLabel = [UILabel new];
        manLabel.text = @"♂";
        manLabel.textColor = CustomColor(26, 177, 153, 1);
        manLabel.font = CustomUIFont(20);
        [self addSubview:(self.manLabel = manLabel)];
        manLabel.textAlignment = 1;
        
        
        UILabel *weomanLabel = [UILabel new];
        weomanLabel.text = @"♀";
        weomanLabel.textColor = CustomColor(194, 116, 103, 1);
        weomanLabel.font = CustomUIFont(20);
        [self addSubview:(self.weomanLabel = weomanLabel)];
        weomanLabel.textAlignment = 1;
        
        WeakSelf
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).offset(50);
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        
        
        [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconImageView.mas_right).offset(20);
            make.centerY.equalTo(weakSelf);
            make.right.equalTo(weakSelf);
            make.height.mas_equalTo(30);
        }];
        
        [switchView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf).offset(-30);
            make.centerY.equalTo(weakSelf);
            make.height.mas_equalTo(30);
        }];
        
        [manLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(switchView.mas_left);
            make.centerY.equalTo(weakSelf);
            make.height.mas_equalTo(30);
            make.width.mas_equalTo(30);
        }];
        
        [weomanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(switchView.mas_right);
            make.centerY.equalTo(weakSelf);
            make.height.mas_equalTo(30);
            make.width.mas_equalTo((30));
        }];
        
    }
    return self;
}


-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        DDLog(@"开");
        [[NSUserDefaults standardUserDefaults]setObject:@"10" forKey:@"isButtonOn"];
    }else {
        [[NSUserDefaults standardUserDefaults]setObject:@"20" forKey:@"isButtonOn"];
    }

    if (self.isButtonOnBlock){
        self.isButtonOnBlock(isButtonOn);
    }
    
}


@end
